"""
    基于select的并发服务模型
    使用类
"""

# from select import *
# from socket import *
# class EpollServer:
#     def __init__(self,host="",port=0):
#
#
#
#
# def connect_client(connfd):
#     # 处理客户端连接
#     connfd, addr=map[fd].accept()
#     print("Connect from", addr)
#     connfd.setblocking(False)
#     ep.register(connfd, EPOLLIN | EPOLLERR)  # 增加关注对象
#     map[connfd.fileno()]=connfd
#
# def handle_client(connfd):
#     # 处理客户端消息
#     data=map[fd].recv(1024)
#     # 处理客户端退出
#     if not data:
#         ep.unregister(fd)  # 不在关注
#         map[fd].close()
#         del map[fd]
#         return
#     print(data.decode())
#     map[fd].send(b'Thanks')
#
#
# def main():
#     # 创建监听套接字
#     sock=socket()
#     sock.bind(ADDR)
#     sock.listen(3)
#     # 配合非阻塞IO
#     sock.setblocking(False)
#
#     ep=epoll()
#     map={sock.fileno(): sock}
#     ep.register(sock, EPOLLIN)
#
#     # 循环监控关注IO的发生
#     while True:
#         events=ep.poll()
#         for fd, event in events:
#             if fd == sock.fileno():
#                connect_client(fd)
#             elif event == EPOLLIN:
#                 handle_client(fd)
#
#
#
# if __name__ == '__main__':
#     ep=EpollServer(host="0.0.0.0",port=1234)
#     ep.server_forever()
#
#


